import Cookies from 'js-cookie'
import { Module } from 'vuex'
import { GloableState } from '../index'

const state = {
  sidebar: {
    opened: Cookies.get('sidebarStatus') === '1', // 0: false 1: true
    withoutAnimation: false
  }
}

export type AppState = typeof state

const mutations = {
  TOGGLE_SIDEBAR: (state:AppState) => {
    if (state.sidebar.opened) {
      Cookies.set('sidebarStatus', '0')
    } else {
      Cookies.set('sidebarStatus', '1')
    }
    state.sidebar.opened = !state.sidebar.opened
  }
}

const actions = {
}

const app: Module<AppState, GloableState> = {
  namespaced: true,
  state,
  mutations,
  actions
}

export default app
